#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <queue>
#include <cstdio>
#include <string>
#include <stack>
#include <set>
#define IOS ios::sync_with_stdio(false), cin.tie(0)
using namespace std;
typedef long long ll;
ll p[1100000];
int main()
{
    IOS;
    ll n,d;
    cin>>n>>d;
    for(ll i=1;i<=n;i++){
        cin>>p[i];
    }
    sort(p+1,p+1+n);
    ll ans=0;
    for(ll i=1;i<n;i++){
        ll l=i+1,r=n;
        while(l<=r){
            ll mid=(l+r)>>1;
            if(p[i]+d>=p[mid]){
                l=mid+1;
            }
            else r=mid-1;
        }
        ans+=(l-i-1);
    }
    cout<<ans<<endl;
    getchar();
    getchar();
    return 0;
}
